//-----------------------------------------------------------------------
// <copyright file="WebAccessor.cs" company="Rhys Parry">
//    Copyright Rhys Parry 2009
//    This file is released under the Apache 2.0 License
// </copyright>
//-----------------------------------------------------------------------
namespace Smarts.Core
{
    using System;
    using System.Net;
    using Interfaces;

    public class WebAccessor : IWebAccessor
    {
        private WebClient _webClient;

        public WebAccessor()
        {
            ServicePointManager.Expect100Continue = false;
            _webClient = new WebClient();
        }

        public Uri BaseUri
        {
            get { return new Uri(_webClient.BaseAddress); }
            set { _webClient.BaseAddress = value.AbsoluteUri; }
        }

        public string Get(string address)
        {
            return _webClient.DownloadString(address);
        }

        public void UseCredentials(string username, string password)
        {
            UseCredentials(new NetworkCredential(username, password));
        }

        public void UseCredentials(ICredentials credential)
        {
            _webClient.Credentials = credential;
        }
    }
}